package com.bank.doman.auth.controller;

import com.bank.common.io.RestVo;
import com.bank.doman.auth.io.bo.MenuAddBo;
import com.bank.doman.auth.io.bo.MenuEditBo;
import com.bank.doman.auth.io.vo.MenuVo;
import com.bank.doman.auth.server.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 菜单接口
 */
@Api(tags = "菜单服务")
@RequestMapping("/menu")
@RestController
public class MenuController {

    @Resource
    private MenuService menuService;

    @PostMapping("/create")
    @ApiOperation("创建菜单")
    public RestVo create(@Valid @RequestBody MenuAddBo bo) {
        menuService.create(bo);
        return RestVo.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改菜单")
    public RestVo update(@Valid @RequestBody MenuEditBo bo) {
        menuService.update(bo);
        return RestVo.ok();
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除菜单")
    public RestVo delete(@RequestParam Long id) {
        menuService.delete(id);
        return RestVo.ok();
    }

    @GetMapping("/detail")
    @ApiOperation("获取菜单明细")
    public RestVo<MenuVo> detail(Long id) {
        return RestVo.ok(menuService.getById(id));
    }


    @PostMapping("/tree")
    @ApiOperation("查询树结构的权限")
    public RestVo<List<MenuVo>> tree() {
        return RestVo.ok(menuService.tree());
    }


}
